package com.seo.textgen.spacer;

import org.apache.commons.lang.StringUtils;

public class SpacerTokenTypeClassifier {

	private static final String PUNKT = ".?!,:;";

	private static final String SPACE_AROUND_PUNKT = "—+-*/=";

	private static final String LEFT_BRACKET = "[{(«";

	private static final String RIGHT_BRACKET = "]})»";

	private static final byte[] CHAR_CLASS = new byte[0x10000];

	static {
		for (int chr = 0; chr < CHAR_CLASS.length; chr++) {
			if (StringUtils.contains(PUNKT, (char) chr)) {
				CHAR_CLASS[chr] = (byte) SpacerTokenType.PUNKT;

			} else if (StringUtils.contains(SPACE_AROUND_PUNKT, (char) chr)) {
				CHAR_CLASS[chr] = (byte) SpacerTokenType.SPACE_AROUND_PUNKT;

			} else if (StringUtils.contains(LEFT_BRACKET, (char) chr)) {
				CHAR_CLASS[chr] = (byte) SpacerTokenType.LEFT_BRACKET;

			} else if (StringUtils.contains(RIGHT_BRACKET, (char) chr)) {
				CHAR_CLASS[chr] = (byte) SpacerTokenType.RIGHT_BRACKET;

			} else {
				CHAR_CLASS[chr] = (byte) SpacerTokenType.WORD;
			}
		}
	}

	public static byte getSpacerTokenType(String token) {
		return CHAR_CLASS[token.charAt(0)];
	}

}
